Centos6.7搭建Rsyslog日志服务器

您所在的位置:网站首页 rsyslog syslog_options Centos6.7搭建Rsyslog日志服务器

Centos6.7搭建Rsyslog日志服务器

2023-02-26 21:38| 来源: 网络整理| 查看: 265

前言:

随着机房内的服务器和网络设备增加,日志管理和查询就成了让系统管理员头疼的事。

系统管理员遇到的常见问题如下:

1、日常维护过程中不可能登录到每一台服务器和设备上去查看日志; 2、网络设备上的存储空间有限,不可能存储日期太长的日志,而系统出现问题又有可能是很久以前发生的某些操作造成的; 3、在某些非法入侵的情况下,入侵者一般都会清除本地日志,清除入侵痕迹; 4、zabbix等监控系统无法代替日志管理,无法监控如系统登录、计划任务执行等项目。

基于上述原因,在当前的网络环境中搭建一台用于日志集中管理的Rsyslog日志服务器就显得十分有必要了。

Rsyslog服务的优点如下:

1、Rsyslog服务器可以大多数的网络设备支持,在网络设备的系统设备选项中大多都有远程日志服务的配置选项。只需要填写上IP地址和端口(大多数设备已经默认是514了),然后确定就可以了; 2、Linux服务器只需要在本地的Rsyslog服务配置中加入简单的一行就可以将日志发送到日志服务器,布署和配置起来十分简单; 3、通过软件(如evtsys)也可以支持Windows服务器,布署和配置也不是很难,但是有些软件是要收费的; 4、搭配前端的loganalyzer等软件,可以轻松实现图形化管理和查询日志。

一、Rsyslog服务器的安装与配置1、清空iptabels, 关闭selinux避免安装过中报错

清空iptables

iptables -Fservice iptables save

关闭selinux

setenforce 0vim /etc/selinux/conifg

将配置文件中的 SELINUX=enforcing 修改为: SELINUX=disabled

2、yum安装LAMP环境及rsyslog、rsyslog mysql支持模块yum install -y mysql-server mysql-devel libcurl-devel net-snmp-devel php php-gd php-xml php-mysql httpd rsyslog rsyslog-mysql3、设置mysqld和httpd开机启动,并启动服务chkconfig mysqld onchkconfig httpd onservice mysqld startservice httpd start4、修改mysql的root密码mysqladmin -u root password "你的密码"

修改密码后就可以使用如下命令登录mysql

mysql -u root -p5、修改mysql的配置文件,支持uft8

因为通过 yum安装的mysql是不支持uft8的,在收集Windows服务器的日志和某些支持中文的设备的情况下,收集到的日志无法正确显示,因此需要修改mysql配置文件支持中文显示。

配置文件全文如下:

[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0character_set_server=utf8init_connect='SET NAMES utf8'default-character-set=utf8[mysql]default-character-set=utf8[mysql.server]default-character-set=utf8[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.piddefault-character-set=utf8[client]default-character-set=utf8

重启mysqld服务

service mysqld restart6、导入Rsyslog数据库到mysql

Rsyslog的mysql数据库默认文件是:

/usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql

在rsyslog-mysql相应版本的文件夹中 你可以使用下列命令中查询到:

echo $(rpm -ql rsyslog-mysql | grep sql$)

使用如下命令将文件导入到mysql:

mysql -u root -p ALTER DATABASE `Syslog` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;#修改相应数据表的字符集mysql> alter table SystemEvents default character set =utf8;mysql> alter table SystemEventsPorperties default character set =utf8;

查看修改后的效果:

#查看数据库的字符集设置mysql> show variables like 'character%';#查看Systlog数据库所有表的字符集设置mysql> use Syslog;mysql> show table status from Syslog\G;8、创建Rsyslog数据库用户

登录mysql创建Rsyslog的数据库用户logger

#登录mysqlmysql -u root -p#创建用户 mysql> grant all privileges on Syslog.* to 'rsyslog'@'localhost' identified by '147258'; mysql> flush privileges; mysql> exit;9、修改rsyslog配置文件vim /etc/sysconfig/rsyslog

配置文件如下:

# Options for rsyslogd# Syslogd options are deprecated since rsyslog v3.# If you want to use them, switch to compatibility mode 2 by "-c 2"# See rsyslogd(8) for more detailsSYSLOGD_OPTIONS="-c 2 -r -x -m 180"KLOGD_OPTIONS="-x"

各参数详解: -c 指定运行兼容模式。 -r 指定监听端口。 默认514 -x 在接收客户端消息时,禁用DNS查找。需和-r参数配合使用。 -m 标记时间戳。单位是分钟,为0时,表示禁用该功能。

10、配置服务端支持rsyslog-mysql模块,并开启UDP服务端口vim /etc/rsyslog.conf

在#### MODULES ####下添加这两行

$ModLoad ommysql.so*.* :ommysql:localhost,Syslog,rsyslog,147258

注:localhost表示本地主机,Syslog为数据库名,rsyslog为数据库的用户,147258为该用户密码

取消下面三行注释

$ModLoad immark$ModLoad imudp$UDPServerRun 514

重启rsyslog服务:

service rsyslog restart11、添加服务端iptables防火墙规则

如果服务端有需要配置iptables规则的话,执行如下命令开放TCP和UDP的514端口

iptables -I INPUT -p tcp --dport 514 -j ACCEPTiptables -I INPUT -p udp --dport 514 -j ACCEPTservice iptables save二 、Loganalyzer安装与配置1、下载Loganalyzer

从Loganalyzer官网下载安装文件到/usr/local/src目录下 最新版本是4.1.3 稳定版本是:3.6.6

2、解压文件并复制源代码到apache的loganalyzer目录cd /usr/local/srctar -zxvf loganalyzer-4.1.3.tar.gzcd loganalyzer-4.1.3mkdir -p /var/www/html/loganalyzer/cp -r src/* /var/www/html/loganalyzer/cp -r contrib/* /var/www/html/loganalyzer/3、生成空的配置文件并设置权限cd /var/www/html/loganalyzer/touch config.phpchmod 666 config.php4、修改php环境

为配合LogAnalyzer对php环境的要求,请修改/etc/php.ini中的内容为:

memory_limit = 512M max_execution_time = 1205、创建apache日志目录# mkdir -p /var/log/httpd/loganalyzer6、配置apache

这部分,请根据apache实际情况操作。以默认系统为例,虚拟主机配置文件都放在/etc/httpd/conf/httpd.conf

配置文件修改如下:

Listen 80ServerAdmin root@localhostServerName log_server:80DocumentRoot "/var/www/html/loganalyzer" Options FollowSymLinks AllowOverride All Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from allErrorLog /var/log/httpd/loganalyzer/error.logLogLevel warnCustomLog /var/log/httpd/loganalyzer/access_log combinedServerSignature On

重启httpd服务

service httpd restart7、Loganalyzer初始化配置

在浏览器输入网址,进入安装向导 访问http://serverip:80 一共8个步骤,这里只将需要修改的步骤列出,其余只需要”Next”即可

第3步:”Enable User Database”选择“Yes”;

第4、5二个步骤是指定用户数据库信息(数据库指定为:Syslog)和创建用户

第7步:”Source Type” 选择 “MYSQL Native”并在下载配置数据库信息 这里写图片描述

第8步Finish后,完成安装就可登录并查看日志信息了。

三 、Linux客户端配置

Centos默认都会安装rsyslog。

1、确认rsyslog服务是否启动chkconfig | grep rsyslog

如果没有设置为开机启动,执行如下命令:

chkconfig rsyslog onservice rsyslog start2、配置Rsyslog客户端发送本地日志到服务端vim /etc/rsyslog.conf

在末行添加一行:

*.* @192.168.7.201

注:192.168.7.201 为日志服务器端IP地址

3、重启Rsyslog服务service rsyslog restart

这时在服务端刷新就可以看到相关日志信息了。

四 、Windows客户端配置

Loganalyzer官网推荐在Winodws上使用Winsyslog来实现日志数据的收集和发送,但是这个软件是收费的。这里用一个开源的软件Evtsys,但这个软件也有个问题无法在Server 2012以上的系统中使用,在Server 2008中是没有问题的

Evtsy官网由于是布署在google服务器上的因此现在无法访问,可以到网上去搜索下载。 下载后的文件解压将里面的evtsys.exe文件放到c:\windows\System32目录下,然后运行cmd执行下面的命令:

evtsys -i -s 10 -h log-server-ip -p 514 net start evtsys

只要看到最后的安装成功即可。 以下附上命令的详细参数

Version: 4.4 (32-bit) Usage: evtsys.exe -i|-u|-d [-h host] [-b host] [-f facility] [-p port] [-s minutes] [-l level] [-n] -i Install service -u Uninstall service -d Debug: run as console program -h host Name of log host -b host Name of secondary log host (optional) -f facility Facility level of syslog message -l level Minimum level to send to syslog.\n", stderr); 0=All/Verbose, 1=Critical, 2=Error, 3=Warning, 4=Info -n Include only those events specified in the config file. -p port Port number of syslogd -q bool Query the Dhcp server to obtain the syslog/port to log to (0/1 = disable/enable) -s minutes Optional interval between status messages. 0 = Disabled Default port: 514 Default facility: daemon Default status interval: 0 Host (-h) required if installing.

这时在刷新Loganalyzer就可以看到相关日志了.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3